﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RaytracerLib.MathLib;
using System.ComponentModel;

namespace Raytracer.PropertyGridDecorators
{
    public class ColorFloatProperties
    {
        public readonly Action<ColorFloat> Setter;
        public readonly Func<ColorFloat> Getter;

        public ColorFloatProperties(Func<ColorFloat> a_getter, Action<ColorFloat> a_setter)
        {
            Getter = a_getter;
            Setter = a_setter;
        }

        [TypeConverter(typeof(SingleConverter))]
        public float R
        {
            get
            {
                return Getter().R;
            }
            set
            {
                Setter(new ColorFloat(value, G, B));
            }
        }

        [TypeConverter(typeof(SingleConverter))]
        public float G
        {
            get
            {
                return Getter().G;
            }
            set
            {
                Setter(new ColorFloat(R, value, B));
            }
        }

        [TypeConverter(typeof(SingleConverter))]
        public float B
        {
            get
            {
                return Getter().B;
            }
            set
            {
                Setter(new ColorFloat(R, G, value));
            }
        }

        public ColorFloat ToColorFloat()
        {
            return new ColorFloat(R, G, B);
        }
    }

    public class ColorFloatReadonlyProperties
    {
        public readonly Func<ColorFloat> Getter;

        public ColorFloatReadonlyProperties(ColorFloat a_color)
        {
            Getter = () => a_color;
        }

        [TypeConverter(typeof(SingleConverter))]
        public float R
        {
            get
            {
                return Getter().R;
            }
        }

        [TypeConverter(typeof(SingleConverter))]
        public float G
        {
            get
            {
                return Getter().G;
            }
        }

        [TypeConverter(typeof(SingleConverter))]
        public float B
        {
            get
            {
                return Getter().B;
            }
        }
    }
}
